﻿
#region 程序集引用区
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using SubSonic.DataProviders;
using SubSonic.Extensions;
using System.Linq.Expressions;
using SubSonic.Schema;
using System.Collections;
using SubSonic;
using SubSonic.Repository;
using System.ComponentModel;
using System.Data.Common;
using SubSonic.Query;
using System.Xml;
using System.Xml.Serialization;
using System.Reflection;

//引用实体层
using WebeTerm.Model;
using WebeTerm.Common;
#endregion

namespace WebeTerm.DbProvider{
    /// <summary>
    /// 文 件 名: CompanyMailPoolDAL.cs
    /// CLR版本 : v2.0.50727
    /// 作   者 : lijun.hu
    /// 版    权: Copyright @2011 lijun.hu(FORCEN HU) 
    /// 电子邮箱：lijun.hu@shinsoft.net
    /// 说    明: 公司邮件队列
    /// 生成日期: 2014年12月5日
    /// </summary>
    public partial class CompanyMailPoolDAL:BaseDAL< CompanyMailPool >{
        
        #region 通用查询
        /// <summary>
        /// 查询系统设置
        /// </summary>
        /// <param name="queryParam">条件</param>
        /// <param name="pages">分页信息</param>
        /// <returns>系统设置</returns>
        public List< CompanyMailPool > SearchCompanyMailPool(CompanyMailPoolQuery queryParam, Pages pages)
        {
            IQueryable< CompanyMailPool > iQuery = QueryCompanyMailPool(queryParam);
            var items = base.SplitPage(iQuery, pages).ToList();
            items.ForEach(l=>{
                { if (l is IModel) { (l as IModel).SetIsLoaded(); } }    
            });
            return items;
        }

        /// <summary>
        /// 计算系统设置数
        /// </summary>
        /// <param name="queryParam">条件</param>
        /// <returns>系统设置数</returns>
        public int SearchCompanyMailPoolCount(CompanyMailPoolQuery queryParam)
        {
            return QueryCompanyMailPool(queryParam).Count();
        } 
        #endregion

        #region 组合查询
        /// <summary>
        /// 设置 公司邮件队列 查询
        /// </summary>
        /// <param name="queryParam">条件</param>
        /// <returns>公司邮件队列</returns>
        public IQueryable< CompanyMailPool > QueryCompanyMailPool(CompanyMailPoolQuery queryParam)
        {
            IQueryable<CompanyMailPool> iQuery = All();
            iQuery = QueryCompanyMailPoolById(queryParam, iQuery);
            iQuery = QueryCompanyMailPoolByMailTypeCode(queryParam, iQuery);
            iQuery = QueryCompanyMailPoolBySubject(queryParam, iQuery);
            iQuery = QueryCompanyMailPoolByContent(queryParam, iQuery);
            iQuery = QueryCompanyMailPoolByTo(queryParam, iQuery);
            iQuery = QueryCompanyMailPoolByCC(queryParam, iQuery);
            iQuery = QueryCompanyMailPoolByBcc(queryParam, iQuery);
            iQuery = QueryCompanyMailPoolByTryCount(queryParam, iQuery);
            iQuery = QueryCompanyMailPoolByLastTryDate(queryParam, iQuery);
            iQuery = QueryCompanyMailPoolByEnqueueDate(queryParam, iQuery);
            iQuery = QueryCompanyMailPoolByTaskStatus(queryParam, iQuery);
            iQuery = QueryCompanyMailPoolByCompanyId(queryParam, iQuery);
            return iQuery;
        }
        #endregion
        
        #region 单条件查询
        /// <summary>
        /// 根据设置 公司邮件队列 查询
        /// </summary>
        /// <param name="queryParam">条件</param>
        /// <param name="iQuery">公司邮件队列 查询</param>
        /// <returns>公司邮件队列 查询</returns>
        protected virtual IQueryable< CompanyMailPool > QueryCompanyMailPoolById(CompanyMailPoolQuery queryParam, IQueryable< CompanyMailPool > iQuery)
        {
            if (queryParam.Id != Guid.Empty)
                iQuery = iQuery.Where(iq => iq.Id == queryParam.Id);
            return iQuery;
        }
        /// <summary>
        /// 根据设置 公司邮件队列 查询
        /// </summary>
        /// <param name="queryParam">条件</param>
        /// <param name="iQuery">公司邮件队列 查询</param>
        /// <returns>公司邮件队列 查询</returns>
        protected virtual IQueryable< CompanyMailPool > QueryCompanyMailPoolByMailTypeCode(CompanyMailPoolQuery queryParam, IQueryable< CompanyMailPool > iQuery)
        {
            if (!string.IsNullOrEmpty(queryParam.MailTypeCode))
                iQuery = iQuery.Where(iq => iq.MailTypeCode.Contains(queryParam.MailTypeCode.Trim()));
            return iQuery;
        }
        /// <summary>
        /// 根据设置 公司邮件队列 查询
        /// </summary>
        /// <param name="queryParam">条件</param>
        /// <param name="iQuery">公司邮件队列 查询</param>
        /// <returns>公司邮件队列 查询</returns>
        protected virtual IQueryable< CompanyMailPool > QueryCompanyMailPoolBySubject(CompanyMailPoolQuery queryParam, IQueryable< CompanyMailPool > iQuery)
        {
            if (!string.IsNullOrEmpty(queryParam.Subject))
                iQuery = iQuery.Where(iq => iq.Subject.Contains(queryParam.Subject.Trim()));
            return iQuery;
        }
        /// <summary>
        /// 根据设置 公司邮件队列 查询
        /// </summary>
        /// <param name="queryParam">条件</param>
        /// <param name="iQuery">公司邮件队列 查询</param>
        /// <returns>公司邮件队列 查询</returns>
        protected virtual IQueryable< CompanyMailPool > QueryCompanyMailPoolByContent(CompanyMailPoolQuery queryParam, IQueryable< CompanyMailPool > iQuery)
        {
            if (!string.IsNullOrEmpty(queryParam.Content))
                iQuery = iQuery.Where(iq => iq.Content.Contains(queryParam.Content.Trim()));
            return iQuery;
        }
        /// <summary>
        /// 根据设置 公司邮件队列 查询
        /// </summary>
        /// <param name="queryParam">条件</param>
        /// <param name="iQuery">公司邮件队列 查询</param>
        /// <returns>公司邮件队列 查询</returns>
        protected virtual IQueryable< CompanyMailPool > QueryCompanyMailPoolByTo(CompanyMailPoolQuery queryParam, IQueryable< CompanyMailPool > iQuery)
        {
            if (!string.IsNullOrEmpty(queryParam.To))
                iQuery = iQuery.Where(iq => iq.To.Contains(queryParam.To.Trim()));
            return iQuery;
        }
        /// <summary>
        /// 根据设置 公司邮件队列 查询
        /// </summary>
        /// <param name="queryParam">条件</param>
        /// <param name="iQuery">公司邮件队列 查询</param>
        /// <returns>公司邮件队列 查询</returns>
        protected virtual IQueryable< CompanyMailPool > QueryCompanyMailPoolByCC(CompanyMailPoolQuery queryParam, IQueryable< CompanyMailPool > iQuery)
        {
            if (!string.IsNullOrEmpty(queryParam.CC))
                iQuery = iQuery.Where(iq => iq.CC.Contains(queryParam.CC.Trim()));
            return iQuery;
        }
        /// <summary>
        /// 根据设置 公司邮件队列 查询
        /// </summary>
        /// <param name="queryParam">条件</param>
        /// <param name="iQuery">公司邮件队列 查询</param>
        /// <returns>公司邮件队列 查询</returns>
        protected virtual IQueryable< CompanyMailPool > QueryCompanyMailPoolByBcc(CompanyMailPoolQuery queryParam, IQueryable< CompanyMailPool > iQuery)
        {
            if (!string.IsNullOrEmpty(queryParam.Bcc))
                iQuery = iQuery.Where(iq => iq.Bcc.Contains(queryParam.Bcc.Trim()));
            return iQuery;
        }
        /// <summary>
        /// 根据设置 公司邮件队列 查询
        /// </summary>
        /// <param name="queryParam">条件</param>
        /// <param name="iQuery">公司邮件队列 查询</param>
        /// <returns>公司邮件队列 查询</returns>
        protected virtual IQueryable< CompanyMailPool > QueryCompanyMailPoolByTryCount(CompanyMailPoolQuery queryParam, IQueryable< CompanyMailPool > iQuery)
        {
            if (queryParam.TryCount != (int)0)
                iQuery = iQuery.Where(iq => iq.TryCount == queryParam.TryCount);
            return iQuery;
        }
        /// <summary>
        /// 根据设置 公司邮件队列 查询
        /// </summary>
        /// <param name="queryParam">条件</param>
        /// <param name="iQuery">公司邮件队列 查询</param>
        /// <returns>公司邮件队列 查询</returns>
        protected virtual IQueryable< CompanyMailPool > QueryCompanyMailPoolByLastTryDate(CompanyMailPoolQuery queryParam, IQueryable< CompanyMailPool > iQuery)
        {
            if (queryParam.LastTryDate != null)
                iQuery = iQuery.Where(iq => iq.LastTryDate == queryParam.LastTryDate);
            return iQuery;
        }
        /// <summary>
        /// 根据设置 公司邮件队列 查询
        /// </summary>
        /// <param name="queryParam">条件</param>
        /// <param name="iQuery">公司邮件队列 查询</param>
        /// <returns>公司邮件队列 查询</returns>
        protected virtual IQueryable< CompanyMailPool > QueryCompanyMailPoolByEnqueueDate(CompanyMailPoolQuery queryParam, IQueryable< CompanyMailPool > iQuery)
        {
            if (queryParam.EnqueueDate != DateTime.MinValue)
                iQuery = iQuery.Where(iq => iq.EnqueueDate == queryParam.EnqueueDate);
            return iQuery;
        }
        /// <summary>
        /// 根据设置 公司邮件队列 查询
        /// </summary>
        /// <param name="queryParam">条件</param>
        /// <param name="iQuery">公司邮件队列 查询</param>
        /// <returns>公司邮件队列 查询</returns>
        protected virtual IQueryable< CompanyMailPool > QueryCompanyMailPoolByTaskStatus(CompanyMailPoolQuery queryParam, IQueryable< CompanyMailPool > iQuery)
        {
            if (queryParam.TaskStatus != (int)0)
                iQuery = iQuery.Where(iq => iq.TaskStatus == queryParam.TaskStatus);
            return iQuery;
        }
        /// <summary>
        /// 根据设置 公司邮件队列 查询
        /// </summary>
        /// <param name="queryParam">条件</param>
        /// <param name="iQuery">公司邮件队列 查询</param>
        /// <returns>公司邮件队列 查询</returns>
        protected virtual IQueryable< CompanyMailPool > QueryCompanyMailPoolByCompanyId(CompanyMailPoolQuery queryParam, IQueryable< CompanyMailPool > iQuery)
        {
            if (queryParam.CompanyId != Guid.Empty)
                iQuery = iQuery.Where(iq => iq.CompanyId == queryParam.CompanyId);
            return iQuery;
        }
        #endregion
    }
}    